package com.sunseagear.wind.modules.monitor.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sunseagear.common.base.http.R;
import com.sunseagear.common.base.mvc.controller.BaseBeanController;
import com.sunseagear.common.base.satoken.entity.LoginUser;
import com.sunseagear.wind.common.aspectj.annotation.Log;
import com.sunseagear.wind.common.aspectj.enums.LogType;
import com.sunseagear.wind.modules.monitor.entity.query.UserOnlineQuery;
import com.sunseagear.wind.modules.sso.service.IOAuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version V1.0
 * @Title: 在线用户
 * @Description: 在线用户
 * @date 2017-05-15 08:18:21
 */
@RestController
@RequestMapping(value = "/monitor/user/online")
@Log(title = "在线用户")
@RequiredArgsConstructor
public class UserOnlineController extends BaseBeanController {

    private final IOAuthService oAuthService;

    /**
     * 根据页码和每页记录数，以及查询条件动态加载数据
     */
    @RequestMapping(value = "list", method = {RequestMethod.GET, RequestMethod.POST})
    @Log(logType = LogType.SELECT)
    @SaCheckPermission("monitor:user:online:list")
    public R<List<LoginUser>> list(UserOnlineQuery query) {
        // 预处理
        return R.success(oAuthService.activeLoginUser(getPage(), query.getLoginIp(),query.getUsername()));
    }

    /**
     * 强制退出
     * @param ids id列表
     * @return 操作结果
     */
    @PostMapping("/forceLogout")
    @Log(title = "用户强制退出")
    public R<Void> forceLogout(@RequestBody Long[] ids) {
        // 强制退出，不想频繁的请求redis没想好怎么处理
        return R.success("强制退出成功");
    }

}
